import { request } from '@umijs/max';
import { PageResponse, FileDetail } from './index';

// 动态信息接口
export interface DynamicInfo {
  id?: number;
  title: string;
  content: string;
  coverId?: number;
  imageList?: FileDetail[];
  videoList?: FileDetail[];
  type: 1 | 2;  // 1-普通动态,2-置顶动态
  status: 0 | 1;  // 0-草稿,1-已发布
  famousPersonId: number;
  date: string;  // 添加动态日期字段
}

export interface AddDynamicDTO  {
  title: string;
  content: string;
  coverId?: number;
  imageIds?: string;
  videoIds?: string;
  type: 1 | 2;  // 1-普通动态,2-置顶动态
  status: 0 | 1;  // 0-草稿,1-已发布
  famousPersonId: number;
  date: string;  // 添加动态日期字段
}

export interface UpdateDynamicDTO extends AddDynamicDTO {
  id: number;
}

// 分页查询请求
export interface DynamicPageRequest {
  pageCurrent: number;
  pageSize: number;
  famousPersonId: number;
  keyword?: string;
  type?: number;
  status?: number;
}

// API接口
export async function getDynamicPage(params: DynamicPageRequest) {
  return request<PageResponse<DynamicInfo>>('/dynamic/page', {
    method: 'POST',
    data: params,
  });
}

export async function addDynamic(data: AddDynamicDTO) {
  return request('/dynamic/back', {
    method: 'POST',
    data,
  });
}

export async function updateDynamic(data: UpdateDynamicDTO) {
  return request('/dynamic/back', {
    method: 'PUT',
    data,
  });
}

export async function deleteDynamic(idList: number[]) {
  const ids = idList.join(',');
  return request(`/dynamic/back/${ids}`, {
    method: 'DELETE',
  });
}

// 添加获取最新动态的接口
export async function getDynamicLatest(famousPersonId: number) {
  return request<DynamicInfo[]>('/dynamic/latest', {
    method: 'GET',
    params: { famousPersonId },
  });
}

// 添加获取动态详情的接口
export async function getDynamicDetail(id: number) {
  return request<DynamicInfo>(`/dynamic/${id}`, {
    method: 'GET',
  });
}